package com.example.blog.controller;

import com.example.blog.model.Comment;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("comment")
public class CommentController extends BaseController{
    private SqlSession sqlSession;

    public CommentController(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    @RequestMapping("signIn")
    private String signIn(Comment comment){
        if(comment.getUserId()==null){
            request.setAttribute("error","sign in first");
            return "/index.jsp";
        }
        sqlSession.insert("comment.create",comment);
        comment=sqlSession.selectOne("comment.queryById",comment.getId());
        session.setAttribute("comment",comment);

        return "redirect:/article.jsp";
    }




}
